#include <algorithm>
#include <cstdint>
#include <iostream>
#include <istream>
using ll = int64_t;

const ll maxn = 1e5+7;
struct S{
    ll c,t;
    inline bool operator<(const S&other)const{
        return t<other.t;
    }
}h[maxn],l[maxn];
ll n,m,q;

static inline void solve(){
    std::cin>>n>>m>>q;
    for(ll i=1;i<=n;i++)h[i]={0,0};
    for(ll i=1;i<=m;i++)l[i]={0,0};
    for(ll i=1;i<=q;i++){
        ll opt,x,c;
        std::cin>>opt>>x>>c;
        if(opt==0){
            h[x]={c,i};
        }else{
            l[x]={c,i};
        }
    }
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=m;j++){
            if(h[i].c==0&&l[j].c==0){
                std::cout<<"0 ";
                continue;
            }
            std::cout<<std::max(h[i],l[j]).c<<" ";
        }
        std::cout<<"\n";
    }
}

int main(){
    std::iostream::sync_with_stdio(false);
    std::cin.tie(nullptr);

    ll T;
    std::cin>>T;
    while(T--)solve();
}